#!/bin/bash
# 阿里宝宝电商平台 - 启动脚本

echo "=========================================="
echo "阿里宝宝电商平台 - Web前端启动脚本"
echo "=========================================="

# 检查Python环境
if ! command -v python3 &> /dev/null; then
    echo "错误: 未找到Python3，请先安装Python3"
    exit 1
fi

# 检查pip
if ! command -v pip3 &> /dev/null; then
    echo "错误: 未找到pip3，请先安装pip3"
    exit 1
fi

echo "正在检查Python依赖..."

# 安装依赖
pip3 install -r requirements.txt

if [ $? -ne 0 ]; then
    echo "错误: 依赖安装失败"
    exit 1
fi

echo "依赖安装完成！"
echo ""

# 检查后端模块
echo "正在检查后端模块..."
python3 -c "
import sys
import os
sys.path.insert(0, '../models')
try:
    from integrated_system import user_manager, Product
    from cart import Cart, CartItem
    from order import Order, OrderManager
    print('✓ 后端模块检查通过')
except ImportError as e:
    print(f'✗ 后端模块导入失败: {e}')
    print('请确保后端模块文件存在')
    sys.exit(1)
"

if [ $? -ne 0 ]; then
    echo "错误: 后端模块检查失败"
    exit 1
fi

echo ""
echo "=========================================="
echo "启动Web服务器..."
echo "=========================================="
echo "服务器地址: http://localhost:8000"
echo "API文档: http://localhost:8000/api"
echo ""
echo "按 Ctrl+C 停止服务器"
echo "=========================================="

# 启动服务器
python3 server.py
